package org.lucky.controller;

import cn.shuibo.annotation.Decrypt;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.lucky.service.impl.UserServiceImpl;
import org.lucky_common.domain.ParseParamObj;
import org.lucky_common.domain.User;
import org.lucky_common.util.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class UserController {
    @Resource
    private UserServiceImpl userService;
    @PostMapping("/user/register")
    //    @Encrypt
    @Decrypt
    public AjaxResult register(@Validated @RequestBody User user){
        return userService.saveWithCode(user);
    }

    @PostMapping("/user/getUser")
    //    @Encrypt
    @Decrypt
    public AjaxResult getUser(@RequestBody ParseParamObj parseParamObj){
        User inviteCode = userService.getOne(new QueryWrapper<User>().eq("inviteCode", parseParamObj.getRef()));
        return AjaxResult.success(inviteCode);
    }
}
